export default {
	//数据
	data() {
		return {
			curId: 0,
			//登录参数
			loginData: {
				userAccount: "",
				userPassword: "",
			},

		}
	},
	created() { //调用方法
	},
	mounted() {
		// 内容版块获取浏览器尺寸
		var autoDivHeight = document.getElementById('Login');
		var deviceWidth = document.documentElement.clientWidth;
		var deviceHeight = document.documentElement.clientHeight;
		autoDivHeight.style.width = (Number(deviceWidth) -0) + 'px'; //数字是页面布局宽度差值
		autoDivHeight.style.height = (Number(deviceHeight) - 120) + 'px'; //数字是页面布局高度差

	},
	methods: { //写函数方法
		/*平台账号登录*/
		userLogin: function() {
			let that = this;

			if(! that.loginData.userAccount ){
        layer.msg('请输入账号！', {
          time: 3000, //3s后自动关闭
        });
			  return;
      };
      if(! that.loginData.userPassword ){
        layer.msg('请输入密码！', {
          time: 3000, //3s后自动关闭
        });
        return;
      }


			that.$post(
					that.urls.platformLogin,
					that.loginData
				)
				.then(function(res) {
					if(res.success) {

            if(res.data.userInfo.userAccountStatus == 0){
              layer.msg('账号被冻结！', {
                time: 3000, //3s后自动关闭
              });
              return;
            }

					  if(res.data.role.roleStatus == 0){
              layer.msg('账号角色被冻结！', {
                time: 3000, //3s后自动关闭
              });
					    return;
            }


						//将用户信息存入sessionStorage
						that.set("token", res.data.token);//token
						that.set("userRole", res.data.role);//角色信息
						that.set("userInfo", res.data.userInfo);//用户信息
//						console.log(res)
						/*成功后跳转到下一个页面*/
						that.jumpPage();
						layer.msg('登录成功！', {
							time: 3000, //3s后自动关闭
						});
					} else {
            layer.msg(res.message, {
              time: 3000, //3s后自动关闭
            });
					}
				})
				.catch(function(err) {
					if(err.response) {
						console.log(err.response)
						//控制台打印错误返回的内容
						layer.msg('登录失败！', {
							time: 3000, //3s后自动关闭
						});
					}
				})
		},
		/*进入首页*/
		jumpPage: function() {
			this.$router.push({
				path: "/index",
			})
		},

	}
}
